import threading

counter = 0

def increment():
    global counter
    local_counter = counter

    local_counter += 1
    counter = local_counter

threads = []
for i in range(1000):
    thread = threading.Thread(target=increment)
    threads.append(thread)
    thread.start()

for thread in threads:
    thread.join()


print(f"执行完后最终counter = {counter}")